package com.study.testSpringBoot.webThree;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

@WebFilter(urlPatterns = {"/hello","/myFilter"})
public class MyFilter implements Filter {
	
	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		System.out.println("filter的初始化方法。。。");
		ServletContext servletContext = filterConfig.getServletContext();
//		ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
//		ctx.getBean("");
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		System.out.println("filter执行功能方法。。。");
		chain.doFilter(request, response);
	}

	@Override
	public void destroy() {
		System.out.println("filter销毁方法。。。");
	}
}
